/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elaborate.h2x.transform.position.schema.state;

import java.util.HashSet;
import java.util.Set;
import juixb.schema.ContentNode;
import juixb.schema.ElementNode;
import juixb.schema.RefNode;
import juixb.schema.SchemaNode;

/**
 *
 * @author lendle
 */
public class ElementStateParser implements StateParser {

    public boolean isApplicable(SchemaNode schemaNode) {
        return (schemaNode instanceof ContentNode);
    }

    public State parseState(StateParsers parsers, SchemaNode schemaNode) {
        ElementNode elementNode=null;
        if(schemaNode instanceof ElementNode){
            elementNode=(ElementNode) schemaNode;
        }
        else{
            RefNode ref=(RefNode) schemaNode;
            elementNode=ref.getReferencedElementNode();
        }
        DefaultElementStateImpl state=new DefaultElementStateImpl();
        state.setElementNode(elementNode);
        Set<State> set=new HashSet<State>();
        set.add(state);
        state.setFirstSet(set);
        state.setLastSet(set);
        return state;
    }
    
}
